package display.controller;

import java.util.Iterator;

import prefuse.visual.VisualItem;
import display.WheelDisplay;
import display.structure.Wheel;

public class WheelSpeedAnimator extends WheelRotateAnimator{
	private long maxTimeStep = WheelDisplay.MAX_TIMESTEP;
	private long m_lasttime = -1;
	private double radPerSec = -1;
	public WheelSpeedAnimator(String group, double radPerSec, Wheel wheel) {
		super(group, radPerSec, wheel);
		this.radPerSec = radPerSec;
	}
	@Override
	public void run(double frac) {
		if ( m_lasttime == -1 )
            m_lasttime = System.currentTimeMillis()-20;
        long time = System.currentTimeMillis();
        long timestep = Math.min(maxTimeStep, time - m_lasttime);
        setAngle((timestep)*0.001*getRadPerSec());
        Iterator items = getVisualization().items(m_group, m_predicate);
        while ( items.hasNext() ) {
        	process((VisualItem)items.next(), 1);
        }
	}
	public void setMaxTimeStep(long maxTimeStep) {
		this.maxTimeStep = maxTimeStep;
	}
	public long getMaxTimeStep() {
		return maxTimeStep;
	}
	public void setRadPerSec(double radPerSec) {
		this.radPerSec = radPerSec;
	}
	public double getRadPerSec() {
		return radPerSec;
	}
}
